<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  
  <link rel="stylesheet" href="plug-in/tools/css/metrole/common.css">
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  
  
  <script type="text/javascript">
  	$(function() {
	    $(".check" ).checkboxradio();
	 });
  </script>
  <style>
    body{
    	background-color:rgb(248,249,251);    	
    }
  	.panelTitle{
  		color:#1aad19;
  		line-height: 40px;
    	height: 40px;
    	font-size: 16px;
    	text-align:center;
    	border-bottom:1px solid #e6e7ea;
    	margin-bottom:50px;
  	}
  	
  	.selectList a{
  		text-decoration: underline;
  	}
  	
  	.container{
  		background-color: white;
  		width: 80%;
    	max-width: 1280px;
    	margin: 0 auto;
    	min-height: 500px;
  	}
  	
  	.demoTable{
  		border-collapse: collapse;  		
  	}
  	
  	.demoTable td{
  		padding-bottom: 40px;
  	}
  	
  	.demoTable .tdTitle{
  		padding-right:10px;  		
  	}
  	
  	.inputxt{
  		height:30px;
  		width:80px;  		
  		text-align: right;
  	}  
  	#balance{
  		text-align:right;
  		padding-right: 15px;
  	}
  </style>
 </head>
 <body style="padding-top:30px">
 <div class="container">
 <div class="panelTitle">
 	请输入信息
 </div>
		<table  class="demoTable">
				<tr>
					<td align="right" style="width:100px;" class="tdTitle">					
					</td>
					<td style="width:100px;">数额</td>
					<td style="width:130px;text-align: center;">增值税</td>
					<td style="width:100px;text-align: right;">增值税</td>					
				</tr>
				<tr>
					<td align="right" style="width:100px;" class="tdTitle">
						<label class="Validform_label">
							销售额:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" type="text" id="input1" onblur="cal()" value="${apply.sellAmount}"> 	 
					</td>
					<td class="value" style="text-align: center;">						
					    <label for="radio-1">增值税</label>
					    <c:choose>
					    	<c:when test="${apply.sellAmountTax != null}">
					    		<input type="checkbox" class="check" name="radio-1" id="radio-1" onchange="calRadio1()" checked="checked">	
					    	</c:when>
					    	<c:otherwise>
					    		<input type="checkbox" class="check" name="radio-1" id="radio-1" onchange="calRadio1()">
					    	</c:otherwise>
					    </c:choose>
					    
					</td>
					<td class="value" id="saleAmountTax" style="text-align: right;">${apply.sellAmountTax}</td>
				</tr>
				<tr>
					<td align="right" class="tdTitle">
						<label class="Validform_label">
							开支:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" type="text" id="input2" value="${apply.spendAmount}">
					</td>
					<td class="value" style="text-align: center;">						
					    <label for="radio-2">增值税</label>
					    <c:choose>
					    	<c:when test="${apply.spendAmountTax != null}">
					    		<input type="checkbox" class="check" name="radio-2" id="radio-2" onchange="calRadio2()" checked="checked">	
					    	</c:when>
					    	<c:otherwise>
					    		<input type="checkbox" class="check" name="radio-2" id="radio-2" onchange="calRadio2()">
					    	</c:otherwise>
					    </c:choose>
					    
					    
					</td>
					<td class="value" id="spendAmountTax" style="text-align: right;">${apply.spendAmountTax}</td>
				</tr>
				<tr>
					<td align="right" class="tdTitle">
						<label class="Validform_label">
							利润:
						</label>
					</td>
					<td class="value" id="balance">${apply.balance}</td>
				</tr>
 			</table>
 			<div style="text-align:center;">
 				<button class="btn btn_primary btn_input" onclick="send()">上传</button>
 			</div>	
	</div>
 </body>
 <script type="text/javascript">
 	$(document).ready(function(){
 		moneyValidate("input1");
 		moneyValidate("input2");
 	});
 	
 	 function cal(){
 		 var input1 = $('#input1').val();
 		 var input2 = $('#input2').val();
 		 input1 =parseFloat(input1);
 		 input2 = parseFloat(input2); 		 
 		 
 		 var balance = input1-input2;
 		 if(!isNaN(balance)){
 			$("#balance").text(balance);	 
 		 }else{
 			$("#balance").text(' ');
 		 } 
 		 
 		 calRadio1();
 		 calRadio2();
 	 }
 	 
 	 function calRadio1(){
 		var val = $('#radio-1').get(0).checked;
 		var input1Value = $('#input1').val();
 		if(val){
 			var result = parseFloat(input1Value)*(1/11);
 			if(!isNaN(result)){
 				$('#saleAmountTax').text(result.toFixed(2));	
 			}else{
 				$('#saleAmountTax').text('');
 			}
 			
 		}else{
 			$('#saleAmountTax').text('');
 		}
 	 }
 	 
 	 function calRadio2(){
 		var val = $('#radio-2').get(0).checked;
 		var inputValue = $('#input2').val();
 		if(val){
 			var result = parseFloat(inputValue)*(1/11);
 			if(!isNaN(result)){
 				$('#spendAmountTax').text(result.toFixed(2));	
 			}else{
 				$('#spendAmountTax').text('');	
 			}
 			
 		}else{
 			$('#spendAmountTax').text('');
 		}
 	 }
 	
 	 function moneyValidate(id){
 		 $("#"+id).keyup(function () {
 	         var reg = $(this).val().match(/^-?\d*\.?\d{0,2}/);
 	         var txt = '';
 	         if (reg != null) {
 	             txt = reg[0];
 	         }
 	         $(this).val(txt);
 	         
 	          
 	     }).change(function () {
 	         $(this).keypress();
 	         var v = $(this).val();
 	         if (/\.$/.test(v))
 	         {
 	             $(this).val(v.substr(0, v.length - 1));
 	         }
 	         
 	         cal();
 	     }); 
 	 }
 	 
 	 function send(){
 		 
 		if($('#input1').val() == ''){
 			alert("请输入销售额");
 			$('#input1').focus();
 			return;
 		} 
 		if($('#input2').val() == ''){
 			alert("请输入开支");
 			$('#input2').focus();
 			return;
 		} 
 		 
 		$.ajax({
 			url:"selectService.do?doAddApply",
 			type:"post",
 			data:{
 				id:"${apply.id}",
 				sellAmount:$('#input1').val(),
 				spendAmount:$('#input2').val(),
 				balanceAmount:$('#balance').text(),
 				spendAmountTax:$('#spendAmountTax').text(),
 				sellAmountTax:$('#saleAmountTax').text(),
 				balance:$('#balance').text()
 			},
 			success:function(d){
 				console.log(d)
  		 		 var msg = "已发送至邮箱 endure75@gmail.com";
 		 		 alert(msg);
 		 		 window.location.href="selectService.do?goMyForm"
 			}
 		});
 		 
 	 }
 	
 </script>
